//Written by Richard Lewis aka Trixmoto (c) 2007

function newform(typ) {
  //clear old form
  if(MyForm!=null) {
    var yes = prompt("This will discard your current form, type 'YES' to continue:","");
    if(yes.toUpperCase()!="YES") { 
      return false;
    }
  }
  
  //create new form
  switch(typ) {
    case "doc":
      MyForm = new uiDockablepanel('',0,false,0,0,'',true,128,'',0,0,0,0,0,0,true,128);
      break;
    case "frm":
      MyForm = new uiForm(2,'',0,'',false,0,0,'',true,241,'',0,0,0,0,0,0,true,320);
      break;
    case "opt":
      MyForm = new uiOptionSheet(323,'',0,0,0,true,465);
      break;
  }
  
  //refresh display
  MyProp = MyForm;
  storeaction();
  return showview();
}

function addobject(typ) {
  //check selected object
  if(MyProp==null) {
    alert('Sorry, no object is selected!');
    return false;
  }
  
  //get parent
  var par = MyForm;  
  if(MyProp.kids!=null) {
    par = MyProp;
  }
  
  //create new object
  var newobj;
  switch(typ) {
    case "act":
      newobj = new uiActivex(par,'Shell.Explorer',0,0,'',true,150,'',0,0,0,0,0,0,true,300);
      break;
    case "but":
      newobj = new uiButton(par,false,'',false,0,'','',0,0,'',true,25,'',0,0,0,0,0,0,true,75);
      break; 
    case "drp":
      newobj = new uiDropdown(par,'',-1,'','',0,'',0,0,'',true,21,'',0,0,0,0,0,0,true,121);
      break;      
    case "edt":
      newobj = new uiEdit(par,'',0,0,'',true,21,'',0,0,0,0,0,0,true,121);
      break;       
    case "chk":
      newobj = new uiCheckbox(par,'',false,0,0,'',true,20,'',0,0,0,0,0,0,true,98);
      break;       
    case "lbl":
      newobj = new uiLabel(par,0,true,'',false,0,0,'',true,17,'',0,0,0,0,0,0,true,65);
      break; 
    case "pan":
      newobj = new uiPanel(par,0,0,'',true,90,'',0,0,0,0,0,0,true,100);
      break; 
    case "rad":
      newobj = new uiRadiobutton(par,'',false,0,0,'',true,20,'',0,0,0,0,0,0,true,98);
      break;      
    case "spn":
      newobj = new uiSpinedit(par,0,0,0,0,0,'',true,21,'',0,0,0,0,0,0,true,121);
      break;      
    case "bar":
      newobj = new uiTrackbar(par,true,10,0,3,0,0,'',true,45,'',0,0,0,0,0,0,true,150);
      break;      
    case "tra":
      newobj = new uiTransppanel(par,0,0,'',true,90,'',0,0,0,0,0,0,true,100);
      break;
    default: 
      alert('Sorry, object type unknown!');
      return false;
  }
  
  //refresh display
  par.kids.push(newobj);
  MyProp = newobj;
  storeaction();
  return showview();
}

function delobject() {
  remobj(MyForm,MyProp);
  MyProp = MyForm;
  storeaction();
  return showview();
}

function remobj(par,obj) {
  //check object found
  if(par==obj) {
    return true;
  }
  //recurse through kids
  var arr = par.kids;
  if(arr!=null) {
    for(var i=0;i<arr.length;i++) {
      if(remobj(arr[i],obj)) {
        par.kids.splice(i,1);
        return false;
      }
    }
  } 
  return false;
}

  